const os = require('os');
const fs = require('fs');
const path = require('path');
const userHomeDir = os.homedir();

// 根据操作系统构建用户数据目录的路径
let appName = 'labelapp';
let userDataPath;
switch (process.platform) {
    case 'darwin': // macOS
        userDataPath = path.join(userHomeDir, 'Library', 'Application Support', appName);
        break;
    case 'win32': // Windows
        userDataPath = path.join(process.env.APPDATA, appName);
        break;
    default:
        userDataPath = path.join(userHomeDir, `.config`, `${appName}`); // Linux and others
}
const dbFilePath = path.join(userDataPath, 'labelstudio.db');
const dbRemotePath = path.join(userDataPath, 'remotes.db');
const datasetsPath = path.join(userDataPath, 'datasets');

// 删除主数据库文件
try {
    if (fs.existsSync(dbFilePath)) {
        fs.unlinkSync(dbFilePath);
        console.log(`Database file (${dbFilePath}) deleted successfully.`);
    } else {
        console.log(`Database file (${dbFilePath}) not found.`);
    }
} catch (err) {
    console.error(`Error deleting database file: ${err}`);
}

// 珊瑚remotes数据库文件
try {
    if (fs.existsSync(dbRemotePath)) {
        fs.unlinkSync(dbRemotePath);
        console.log(`Database file (${dbRemotePath}) deleted successfully.`);
    } else {
        console.log(`Database file (${dbRemotePath}) not found.`);
    }
} catch (err) {
    console.error(`Error deleting database file: ${err}`);
}

// 删除 datasets 目录及其内容
try {
    if (fs.existsSync(datasetsPath)) {
        fs.rmSync(datasetsPath, { recursive: true });
        console.log(`Datasets directory (${datasetsPath}) and its contents deleted successfully.`);
    } else {
        console.log(`Datasets directory (${datasetsPath}) not found.`);
    }
} catch (err) {
    console.error(`Error deleting datasets directory: ${err}`);
}
